home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Controls
/
Visual Basic Controls.iso
/
vbcontrol
/
em7sui_1
/
DAOCON.CL_
/
DAOCON.CL
Wrap
Text File
|
1998-12-15
|
2KB
|
77 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "DAOCon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'connection to the database
Private m_objConnect As Database
'the status of the connection
Private m_bIsConnected As Boolean
Public Function ConnectToDB() As Boolean
'returns true if connected to database, false if not
On Error GoTo trap_err
' open the connection to data source
Set m_objConnect = Workspaces(0).OpenDatabase(App.Path & "\DB401k.mdb", False, True)
m_bIsConnected = True
ConnectToDB = True
Exit Function
trap_err:
Call MsgBox("Could not connect to DB401k.mdb. Make sure that this database is in the application's directory.", vbExclamation, "401k Report")
m_bIsConnected = False
ConnectToDB = False
End Function
Private Sub Class_Initialize()
Set m_objConnect = Nothing
m_bIsConnected = False
End Sub
Private Sub Class_Terminate()
If Not (m_objConnect Is Nothing) Then
'close the connection
m_objConnect.Close
End If
End Sub
Public Property Get IsConnected() As Boolean
IsConnected = m_bIsConnected
End Property
Public Property Get DBConnection() As Database
Set DBConnection = m_objConnect
End Property
Public Function RunRetrieveQuery(sqlString As String) As Recordset
On Error GoTo bad_sql
Set RunRetrieveQuery = m_objConnect.OpenRecordset(sqlString, dbOpenSnapshot, dbReadOnly)
Exit Function
bad_sql:
Set RunRetrieveQuery = Nothing
m_bIsConnected = False
End Function